home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM 1995 Fall / PD-ROM F95.toast / Programming / Programming Utilities / String Magic 1.0 ƒ / FastStrings.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-10  |  1.8 KB  |  71 lines  |  [TEXT/ttxt]

  1. #include <Types.h>
  2. #include <Resources.h>
  3. #include <Memory.h>
  4. #include "FastStrings.h"
  5.  
  6. pascal void GetIndStr2(Str255 theString, short str2ID, short index)
  7. {
  8.     Handle hStr2;
  9.     register char  *strPtr;
  10.     register int i;
  11.     register short indexMOD16;
  12.     short *indexList;
  13.     short numStrings;
  14.     
  15.     *theString = 0;    // Initialize to the empty string.
  16.     
  17.     if ((hStr2 = GetResource('STR2', str2ID)) == nil)
  18.         return;
  19.             
  20.     numStrings = *(short *)*hStr2;
  21.     if (index < 1 || index > numStrings)
  22.         return;
  23.     
  24.     indexList  = ((short *)(*hStr2)) + 1;
  25.     --index;    // Make index zero base, to simplify calculations
  26.     
  27.     strPtr = ((char *)(*hStr2)) + indexList[index>>4];    // index >>4 == index /16
  28.     // strPtr now points to first string in the block of 16
  29.     
  30.     indexMOD16 = index & 0x0F;
  31.     for (i=0; i < indexMOD16; ++i)        // (index & 0x0F) == index % 16
  32.         strPtr += (char *)*(unsigned char *)strPtr + 1;
  33.         
  34.     // Now copy the string into the caller's buffer
  35.     BlockMove((Ptr)strPtr, (Ptr)theString, (Size)*(unsigned char *)strPtr+1);    
  36. }
  37.  
  38.  
  39. pascal void GetIndStr3(Str255 theString, short strIID, short index)
  40. {
  41.     Handle hStr2;
  42.     register char  *strPtr;
  43.     register int i;
  44.     short numStrings;
  45.     short effectiveID;
  46.     short effectiveIndex;
  47.     
  48.     *theString = 0;    // Initialize to the empty string.
  49.     
  50.     --index;    // Make index zero base, to simplify calculations
  51.     effectiveIndex = index & 0x0f;
  52.     effectiveID = ((strIID - 128) << 12) + (index>>4) + 1;
  53.     
  54.     
  55.     if ((hStr2 = GetResource('STR3', effectiveID)) == nil)
  56.         return;
  57.             
  58.     numStrings = *(short *)*hStr2;
  59.     if (effectiveIndex >= numStrings)
  60.         return;
  61.         
  62.     strPtr = ((char *)(*hStr2)) + 2;    // Skip past the Number of strings entry
  63.     
  64.     for (i=0; i < effectiveIndex; ++i)
  65.         strPtr += (char *)*(unsigned char *)strPtr + 1;
  66.         
  67.     // Now copy the string into the caller's buffer
  68.     BlockMove((Ptr)strPtr, (Ptr)theString, (Size)*(unsigned char *)strPtr+1);    
  69.  
  70. }
  71.